24. Exercise: Add a Live Region

L10 40 Content Grouping (2.0) SC

Now it's your turn to complete this exercise yourself!

In this exercise you'll add a live region to your app. We'll also take this opportunity to make a few small improvements to the UI.

1. Change the content descriptor and text dynamically.

In AddGdgFragment.kt, inside the showSnackBarEvent Observer, use bindings to set the button's text and content description after displaying the SnackBar.**

viewModel.doneShowingSnackbar()

binding.button.contentDescription=getString(R.string.submitted)
binding.button.text=getString(R.string.done)


2. Change the button's text from OK to SUBMIT.

In add_gdg_fragment.xml, Button's text assignment:**

android:text="@string/submit"


3. Add a liveRegion to the button, and set it to "polite":

android:accessibilityLiveRegion="polite"


As an added bonus, let's make few small UI changes that will make a big impact!:

1. Enlarge the button.

In add_gdg_fragment.xml, change the button's width and height to wrap_content:

android:layout_width="wrap_content"
android:layout_height="wrap_content"


2. Now remove that ugly background color!

Delete backgroundTint, textColor, and textSize attributes from the button.


3. Allow the theme to set textViewIntro's text color.

Delete the textColor attribute from the textViewIntro TextView.


Run the app again and see how much better the UI looks!


If you want to start at this step, you can download this exercise from: Step.11-Exercise-Add-Live-Region.

You will find plenty of //TODO comments to help you complete this exercise, and if you get stuck, go back and watch the video again.

Once you’re done, you can check your solution against the solution we’ve provided here: Step.11-Solution-Add-Live-Region, or using this git diff.

Task Description:

Complete the following tasks to add a live region to your app, and make some improvements to the UI.

Task List:

Task Feedback:

Good work, the more Material the better!